package cn.wit.summit.chwan.widgets;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Html;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.Stat.StatFactory;
import cn.wit.summit.chwan.utils.CommonUtil;
import cn.wit.summit.chwan.utils.DensityUtil;
import cn.wit.summit.chwan.utils.StringUtils;

/**
 * Created by tangbl on 2018/4/20.
 */

public class ShareBottomDialog extends AlertDialog implements View.OnClickListener {

    private TextView shareWXFriendsTv;
    private TextView shareWXXQTv;
    private TextView shareQQTv;
    private TextView sharedialogCancelTv;

    private int width;
    private String shareUrl;
    private String gameId;
    private int from;

    public ShareBottomDialog(@NonNull Activity context, int width, String shareUrl, int from, String gameId) {
        super(context);
        this.width = width;
        this.shareUrl = shareUrl;
        this.gameId = gameId;
        this.from = from;
    }

    public ShareBottomDialog(@NonNull Activity context, int width, String shareUrl, int from) {
        super(context);
        this.width = width;
        this.shareUrl = shareUrl;
        this.from = from;
        this.gameId = "";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setCancelable(true);  //是否获取界外焦点
        Window dialogWindow = getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = width; //设置宽度
        dialogWindow.setAttributes(lp);
        dialogWindow.setWindowAnimations(R.style.dialog_share_anim);

        setContentView(R.layout.dialog_share_bottom_view);

        shareWXFriendsTv = findViewById(R.id.shareWXFriendsTv);
        shareWXXQTv = findViewById(R.id.shareWXXQTv);
        shareQQTv = findViewById(R.id.shareQQTv);
        sharedialogCancelTv = findViewById(R.id.sharedialogCancelTv);

        shareWXFriendsTv.setOnClickListener(this);
        shareWXXQTv.setOnClickListener(this);
        shareQQTv.setOnClickListener(this);
        sharedialogCancelTv.setOnClickListener(this);
    }

    //from;//1，APP分享；2，游戏详情分享；3，资讯分享；4，社区分享；5，活动分享（H5）;6.直播
    @Override
    public void onClick(View v) {
        dismiss();
        StatFactory.getInstance().sendShare(getContext(), gameId, from+"", "");
        switch (v.getId()) {
            case R.id.shareWXFriendsTv:
                CommonUtil.shareToOne(getContext(), 0, shareUrl, 2, from);
                break;
            case R.id.shareWXXQTv:
                CommonUtil.shareToOne(getContext(), 1, shareUrl, 2, from);
                break;
            case R.id.shareQQTv:
                CommonUtil.shareToOne(getContext(), 2, shareUrl, 2, from);
                break;
            case R.id.sharedialogCancelTv:
                break;
        }
    }
}
